﻿using System.Linq.Expressions;
using System.Reflection;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Swashbuckle.AspNetCore.SwaggerUI;
using TodoApp.Application;
using TodoApp.EntityFrameworkCore;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddTodoApplication();


builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(options =>
{
    options.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo()
    {
        Title = "Todo接口文档",
        Version = "v1",
        Description = "这个WebApi项目是练手写着玩的，不要用于生产环境。"
    });
    var dir = AppContext.BaseDirectory;
    var fileName = Assembly.GetExecutingAssembly().GetName().Name + ".xml";
    options.IncludeXmlComments(Path.Combine(dir, fileName), true);
});

builder.Services.AddEntityFrameworkCore<TodoDbContext>(options =>
{
    options.UseSqlServer(builder.Configuration.GetConnectionString("Live202212"));
}); 

var app = builder.Build();

app.UseSwagger();
app.UseSwaggerUI(options =>
{
    options.RoutePrefix = "";

    options.SwaggerEndpoint("/swagger/v1/swagger.json", "Todo接口文档");
    options.DocExpansion(DocExpansion.None);
});

app.UseAuthorization();

app.MapControllers();

app.Run();

